using System;
using System.Collections.Generic;
using System.Text;

using NHibernate;
using Zwms.Data.BusinessObjects;
using Zwms.Data.Base;
using Zwms.Data.CommonObject;
using NHibernate.Criterion;
using System.Reflection;

namespace Zwms.Data.ManagerObjects
{
    public partial interface IWhShelfManager : IManagerBase<Zwms.Data.BusinessObjects.WhShelf, string>
    {
        // Get Methods
        WhShelf GetById(System.String shelfCode, System.String warehousCode, System.String areaCode);
    }

    partial class WhShelfManager : ManagerBase<Zwms.Data.BusinessObjects.WhShelf, string>, IWhShelfManager
    {
        #region Constructors

        public WhShelfManager()
            : base()
        {
        }
        public WhShelfManager(INHibernateSession session)
            : base(session)
        {
        }

        #endregion

        #region Get Methods

        public override WhShelf GetById(string id)
        {
            string[] keys = id.Split('^');

            if (keys.Length != 3)
                throw new Exception("Invalid Id for WhShelfManager.GetById");

            return GetById(keys[0], keys[1], keys[2]);
        }
        public WhShelf GetById(System.String shelfCode, System.String warehousCode, System.String areaCode)
        {
            ICriteria criteria = Session.GetISession().CreateCriteria(typeof(WhShelf));

            criteria.Add(NHibernate.Criterion.Expression.Eq("ShelfCode", shelfCode));
            criteria.Add(NHibernate.Criterion.Expression.Eq("WarehouseCode", warehousCode));
            criteria.Add(NHibernate.Criterion.Expression.Eq("AreaCode", areaCode));

            WhShelf result = (WhShelf)criteria.UniqueResult();

            if (result == null)
                throw new NHibernate.ObjectDeletedException("", null, null);

            return result;
        }
        #endregion
    }
}